//Copyright 2011  sacha schutz istdasklar@gmail.com

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License as
//published by the Free Software Foundation; either version 2 of
//the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.
//or for later versions approved by KDE e.V.

//Copyright 2011  schutz istdasklar@gmail.com

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License as
//published by the Free Software Foundation; either version 2 of
//the License or (at your option) version 3 or any later version
//accepted by the membership of KDE e.V. (or its successor approved
//by the membership of KDE e.V.), which shall act as a proxy
//defined in Section 14 of version 3 of the license.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "glasgow_coma_scale_formwidget.h"
#include "ui_glasgow_coma_scale_formwidget.h"

#include "formula/glasgow_coma_scale_formula.h"
#include <QDebug>
Glasgow_Coma_Scale_FormWidget::Glasgow_Coma_Scale_FormWidget(QWidget *parent) :
        AbstractFormWidget(new Glasgow_Coma_Formula,parent),
        ui(new Ui::Glasgow_Coma_Scale_FormWidget)
{
    ui->setupUi(this);


    connect(ui->eyesButtonGroup,SIGNAL(buttonClicked(int)),this,SLOT(setResult()));
    connect(ui->verbalButtonGroup,SIGNAL(buttonClicked(int)),this,SLOT(setResult()));
    connect(ui->motorButtonGroup,SIGNAL(buttonClicked(int)),this,SLOT(setResult()));




}

Glasgow_Coma_Scale_FormWidget::~Glasgow_Coma_Scale_FormWidget()
{
    delete ui;
}



void Glasgow_Coma_Scale_FormWidget::setResult()
{


    Glasgow_Coma_Formula * f = (Glasgow_Coma_Formula*)(formula());

    int Y=1;
    int V=1;
    int M=1;
    int i;

    i=1;
    foreach ( QAbstractButton * eyeBtn, ui->eyesButtonGroup->buttons())
    {
        if ( eyeBtn->isChecked())
            Y = i;
        ++i;
    }

    i=1;
    foreach ( QAbstractButton * verbalBtn, ui->verbalButtonGroup->buttons())
    {
        if ( verbalBtn->isChecked())
            V = i;
         ++i;
    }

    i=1;
    foreach ( QAbstractButton * motorBtn, ui->motorButtonGroup->buttons())
    {
        if ( motorBtn->isChecked())
            M = i;
         ++i;
    }


    ui->resultSpinBox->setValue(f->result(Y,V,M));


}
